<script type="text/javascript">
    $(function() {
        $("#desde").datepicker({dateFormat: 'dd/mm/yy', changeMonth: true, changeYear: true});
        $( "#hasta" ).datepicker({dateFormat: 'dd/mm/yy', changeMonth: true, changeYear: true});
        $( "#numero" ).click(function() {
            $( "#desde" ).val("");
            $( "#hasta" ).val("");
        });
        $( "#desde", "#hasta"   ).click(function() {
            $( "#numero" ).val("");
        });
    });
    
    function popup(url,idtr) {
        var  desde=$( "#desde" ).val();
        var  hasta=$( "#hasta" ).val();
        var  filtro_pagos=$("input[name='filtro_pagos']:checked").val();
        var  con_venta=$("#con_venta").is(':checked') ? 1 : 0;

        desde=  desde.split("/").join("_");
        hasta=  hasta.split("/").join("_");
     
        url = url+'/desde/'+desde+'/hasta/'+hasta+'/filtro_pagos/'+filtro_pagos+'/con_venta/'+con_venta;
      
        var newwindow = window.open(url,'name','height=200,width=150');
        if (window.focus) {newwindow.focus();}
        return false;
    }
</script> 
<style type="text/css">
    .seleccionada tr{background-color: #D9EDF7;}
    .tabla_reducida td{padding-top: 0px;padding-bottom: 0px;}
</style>

<div class="row-fluid">
    <div class="well well-small">
        <h5 >Ventas</h5>
        <form name="form_busqueda" class="form-inline noPrint" method="GET" action="<?php echo $this->baseUrl(); ?>/admin/impresiones/ventas">
            <label class="control-label">Desde</label>
            <input id="desde" name="desde" value="<?php echo empty($this->desde) ? 1 : $this->desde; ?>" class="input-small" type="text" />
            <label class="control-label">Hasta</label>
            <input id="hasta" name="hasta"   value="<?php echo empty($this->hasta) ? 1 : $this->hasta; ?>" class="input-small" type="text" />
            <label class="control-label">Nro Credito</label>
            <input id="numero" name="numero"   value="<?php echo $this->numero; ?>" class="input-small" type="text" />
            <label>
                <input type="radio" name="filtro_pagos" value="todos" <?php if($this->filtros_pagos == "todos"){echo 'checked="true"';} ?> checked="true" >Todos 
                <input type="radio" name="filtro_pagos" value="impresos" <?php if($this->filtros_pagos == "impresos"){echo 'checked="true"';} ?> >Impresos
                <input type="radio" name="filtro_pagos" value="noimpresos" <?php if($this->filtros_pagos == "noimpresos"){echo 'checked="true"';} ?> >No Impresos
            </label>

            <input class="btn" name="buscar" value="Buscar" type="submit" />
        </form>
        <div class="row-fluid ">
            <div class="span12">
                <?php 
                $subtitulo = '<b>' . count($this->pagos) . '</b> Pagos encontrados entre <b>' . $this->desde . '</b> a <b>' . $this->hasta . '</b>';
                echo $subtitulo;
                ?>
                <div class="btn-toolbar pull-right">
                    <label>
                        <input type="checkbox" name="con_venta" id="con_venta"  <?php echo $this->con_venta ? "checked" : "" ?>   > Inprimir Venta &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;    
                        <button type="button" onclick="popup('<?php echo $this->baseUrl(); ?>/admin/impresiones/imprimirlistadosdepagospdf')" class="btn btn-inverse noPrint"><i class=" icon-print icon-white"></i> Re Imprimir Todos</button>
                    </label>
                </div>
            </div>

            <table class="tabla_reducida" id="ventas">
                <thead>
                    <tr><th>Fecha</th><th>Nro Pago.</th><th>Nro Cuota.</th><th>Nro Cred.</th><th>DNI</th><th>Apellido</th><th>Nombres</th><th>Monto</th><th>Fecha Impreso</th><th></th></tr>
                </thead>
                <tbody>
                    <?php if (count($this->pagos)): ?>
                        <?php $credito = new Doctrine_Model_Entities_Credito() ?>
                        <?php foreach ($this->pagos as $pago): ?>
                            <tr id="tr<?php echo $pago->getId(); ?>" style="background-color: <?php  if($pago->getFechaReimpreso()){echo '#FFFF80';} ?>" >
                                <td><?php echo $pago->getFecha()->format('d/m/Y'); ?></td>
                                <td><?php echo $pago->getId(); ?></td>
                                <td><?php echo $pago->getCuota()->getNumeroDeCuota(); ?></td>
                                <td><?php echo $pago->getCuota()->getCredito()->getNumero(); ?></td>
                                <td style="width:90px;text-align:center;">
                                    <a href="<?php echo $this->baseUrl("usuarios/busqueda/obternerdatospersona/persona_id/{$pago->getCuota()->getCredito()->getCliente()->getId()}") ?>" onclick="agregaMarcaUrl('<?php echo "#credito{$pago->getCuota()->getCredito()->getId()}" ?>')">
                                        <?php echo $pago->getCuota()->getCredito()->getCliente()->getNroDocumento(); ?>
                                    </a>
                                </td>
                                <td><?php echo $pago->getCuota()->getCredito()->getCliente()->getApellido(); ?></td>
                                <td><?php echo $pago->getCuota()->getCredito()->getCliente()->getNombres(); ?></td>
                                <td><?php echo $pago->getCuota()->getCredito()->getMonto(); ?></td>
                                <td><?php if($pago->getFechaReimpreso()){echo $pago->getFechaReimpreso()->format('d/m/Y');} ?></td>
                                <td> <button type="button" onclick="popup('<?php echo $this->baseUrl(); ?>/admin/impresiones/imprimirpagoindividualpdf/pago_id/<?php echo $pago->getId(); ?>','tr<?php echo $pago->getId(); ?>')" style="padding-top: 0px;padding-bottom: 0px;padding-left: -5px;padding-right: 0spx;"  class="btn btn-inverse input-mini noPrint"><i class="icon-print icon-white" ></i></button><button type="button" onclick="popup('<?php echo $this->baseUrl(); ?>/admin/impresiones/imprimirpagoindividualpdf/pago_id/<?php echo $pago->getId(); ?>/con_venta/1','tr<?php echo $pago->getId(); ?>')" style="padding-top: 0px;padding-bottom: 0px;padding-left: -5px;padding-right: 0spx;"  class="btn btn-inverse input-mini noPrint"><i class="icon-print icon-white" ></i><i class="icon-align-justify icon-white" ></i></button></td>
                            </tr>
                        <?php endforeach; ?>
                    <?php else: ?>
                        <tr><td colspan="11">Sin Resultados</td></tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

<div id="datos" ></div>

 
